245. gcloud storage取代gsutil

WHY

剛好想要查一下gsutil的 rsync指令,
結果官方文件一直跑不出來,
細看才發現

通常,您應該使用 gcloud storage 命令)而不是 gsutil 命令:
gsutil 工具是一個舊版 Cloud Storage CLI,僅進行最低程度的維護。
gsutil 工具不支援使用較新的 Cloud Storage 功能,例如軟刪除和託管式資料夾
gcloud storage 命令需要較少的手動最佳化即可實現最快的上傳和下載速率。

看來我該改程式了。

Note

Gsutil

  1. rsync 同步
gsutil -m rsync -r /home/user/docker-compose/VideoSokoban/MP4Final gs://abc

change 

gcloud storage rsync -r /home/user/docker-compose-yaml/VideoSokoban/MP4Final gs://abc

ref. gcloud storage rsync

  1. signurl 下載權限
gsutil signurl -d 30m gcs-download.json gs://backup/downloadbak/24-4-17.bak

change

gcloud storage sign-url  -d=30m --private-key-file=gcs-download.json gs://backup/downloadbak/24-4-17.bak

但第一次執行時,可能會發生錯誤

ERROR: (gcloud.storage.sign-url) This command requires the pyOpenSSL library. Please install it and set the environment variable CLOUDSDK_PYTHON_SITEPACKAGES to 1 before re-running this command

執行

export CLOUDSDK_PYTHON_SITEPACKAGES=1

ref. gcloud storage sign-url

  1. du 查bucket大小
gcloud storage du gs://abc --summarize --readable-sizes

ref. gcloud storage du

或是在Metrics Explorer ,查詢 Total bytes (v2) 選擇 GCS Bucket。
這邊也有 Total count (v2) 可以查詢加總。
filter可指定bucket name。

完整 api storage.googleapis.com/storage/v2/total_bytes

245-fig.1.png

  1. cors
gsutil cors set example_cors_file.json gs://example_bucket
改
gcloud storage buckets update gs://example_bucket --cors-file=example_cors_file.json

ref.

  1. cp 複製
gsutil cp -n gs://abc/57d51e14-6ea2-409a-9bee-07a832456cf6.jpg .


gcloud storage cp -n  gs://abc/57d51e14-6ea2-409a-9bee-07a832456cf6.jpg .

ref. gcloud storage cp